package com.letoy.study.utils;

import com.letoy.study.config.StoreConfig;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @program:letoy-study-java
 * @author: WeiHaoL
 * @Time: 2021/2/4  下午3:40
 */


public class FileUploadUtil {



    public static boolean uploadFile(MultipartFile file, String filePath){

        if (file.isEmpty()) {
            return false;
        }
        try {
            String filename = file.getOriginalFilename();
            File dest = new File(filePath + filename);
            if (!dest.getParentFile().exists()){
                dest.getParentFile().mkdirs();
            }
            file.transferTo(dest);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
